package com.zuoban.sms.config;


import com.zuoban.sms.properties.SmsProperties;
import com.zuoban.sms.service.SmsService;
import com.zuoban.sms.service.impl.AliyunSmsServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(value = SmsProperties.class)
@ConditionalOnProperty(prefix = "sms",value = "enable",havingValue = "true")
public class SmsConfig {

    @Bean
    public SmsService smsService(SmsProperties smsProperties){
        if (smsProperties.getType().equals(SmsProperties.SmsType.ALIYUN.getPlat())){
            return new AliyunSmsServiceImpl(smsProperties);
        }
        return null;
    }
}
